﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Interactivity.InteractionRequest;
using Prism.Mvvm;
using SPW.Component.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace SPW.GenericDesktop.ViewModels
{
    public class ModuleContainerPopupViewModel : BindableBase, IInteractionRequestAware
    {
        private readonly IEventAggregator _eventAggregator;

        public ModuleContainerPopupViewModel(IEventAggregator eventAggregator)
        {
            this._eventAggregator = eventAggregator;
            SubscribeEvents();
        }

        /// <summary>
        /// 订阅事件
        /// </summary>
        private void SubscribeEvents()
        {
            this._eventAggregator.GetEvent<Infrastructure.Events.DialogEvent>().Subscribe(DialogWithAsync);
        }

        /// <summary>
        /// 对话处理
        /// </summary>
        /// <param name="eventArgs"></param>
        private async void DialogWithAsync(Infrastructure.Events.DialogEventArgs eventArgs)
        {
            //var confirm = new ConfirmMessageDialog("您确认立即退出本应用？");
            FrameworkElement dialogView = null;
            switch (eventArgs.DialogModel)
            {
                case Infrastructure.Events.DialogEventArgs.DialogModelModes.Notice:
                    {
                        dialogView = new NoticeMessage(eventArgs.Message);
                    }
                    break;
                case Infrastructure.Events.DialogEventArgs.DialogModelModes.Confirm:
                    {
                        dialogView = new ConfirmMessage(eventArgs.Message);
                    }
                    break;
            }
            var result = await DialogHost.Show(dialogView, "RootDialog");
            eventArgs.Callback(result);
        }

        public INotification Notification { get; set; }
        public Action FinishInteraction { get; set; }
    }
}
